package cc.telecomdigital.tdstock.adapter;

import java.util.List;

import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import cc.telecomdigital.tdstock.R;

public class CommonListItemAdapter extends BaseAdapter
{
	private LayoutInflater			minflater;
	private List<CommonViewHolder>	list;

	public CommonListItemAdapter(LayoutInflater inflater,
			List<CommonViewHolder> list)
	{
		super();
		this.minflater = inflater;
		this.list = list;
	}

	@Override
	public int getCount()
	{
		// TODO Auto-generated method stub
		return this.list.size();
	}

	@Override
	public Object getItem(int position)
	{
		return position < this.list.size() ? this.list.get(position) : null;
	}

	@Override
	public long getItemId(int position)
	{
		return position < this.list.size() ? this.list.get(position).id : -1l;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent)
	{
		CommonViewHolder commHolder = null;
		if (convertView == null)
		{
			//convertView = minflater.inflate(R.layout.moreitem, null);
			convertView = minflater.inflate(R.layout.list_common_item, null);
			commHolder = new CommonViewHolder();
			commHolder.text = (TextView) convertView
					.findViewById(R.id.more_item_text);
			commHolder.sign = (ImageView) convertView
					.findViewById(R.id.more_item_sign);

			//synchronize with iphone
			commHolder.text.setTextColor(Color.BLACK);
			convertView.setDrawingCacheBackgroundColor(Color.WHITE);

			//synchronize with iphone

			convertView.setTag(commHolder);
		}
		else
		{
			commHolder = (CommonViewHolder) convertView.getTag();
		}
		commHolder.text.setText(this.list.get(position).text.getText());
		commHolder.sign.setImageResource(R.drawable.go_next_icon);
		return convertView;
	}

}
